package com.pbase.data.http.interceptor;

import com.pbase.data.http.listener.OnDataRequestListenerWithProgress;
import com.pbase.data.http.upanddown.ProgressResponseBody;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by goldze on 2017/5/10.
 * 进度条拦截器
 */
public class ProgressInterceptor implements Interceptor {
    private OnDataRequestListenerWithProgress listener;

    public ProgressInterceptor(OnDataRequestListenerWithProgress listener) {
        this.listener = listener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());

        return originalResponse.newBuilder()
                .body(new ProgressResponseBody(originalResponse.body(),listener))
                .build();
    }


}
